#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct Node{
    int val;
    Node* leftN;
    Node* rightN;
};
int n;
int num[1000];
Node* buildBSTree(int l,int r){
    if(l<0||r<0||r<l)
        return nullptr;
    Node* node = new Node();
    node->val=num[l];
    if(l==r){
        node->leftN=nullptr;
        node->rightN=nullptr;
        return node;
    }
    int ll=l+1,lr=r,rl=-1,rr=r;
    for(int i=ll;i<=r;i++){
        if(num[i]>=num[l]){
            //cout<<num[i]<<" "<<num[l]<<endl;
            rl=i;
            lr=i-1;
            break;
        }
    }
    node->leftN=buildBSTree(ll,lr);
    node->rightN=buildBSTree(rl,rr);
    return node;
}
Node* buildMBSTree(int l,int r){
    if(l<0||r<0||r<l)
        return nullptr;
    Node* node = new Node();
    node->val=num[l];
    if(l==r){
        node->leftN=nullptr;
        node->rightN=nullptr;
        return node;
    }
    int ll=l+1,lr=r,rl=-1,rr=r;
    for(int i=ll;i<=r;i++){
        if(num[i]<num[l]){
            //cout<<num[i]<<" "<<num[l]<<endl;
            rl=i;
            lr=i-1;
            break;
        }
    }
    node->leftN=buildMBSTree(ll,lr);
    node->rightN=buildMBSTree(rl,rr);
    return node;
}
queue<int> que;
void printPostOrder(Node* node){
    if(node!=nullptr){
        printPostOrder(node->leftN);
        printPostOrder(node->rightN);
        //cout<<node->val<<" ";
        que.push(node->val);
    }
}
int main(){
    cin>>n;
    int i=0;
    while(i<n){
        cin>>num[i++];
    }


    for(i=0;i<n;i++){
        bool flag1=false,flag2=false;
        bool flag3=false,flag4=false;
        if(num[i+1]<num[i]){
            flag1=true;
        }else{
            flag2=true;
        }
        for(int j=i+1;j<n;j++){
            if(flag1&&flag3&&num[j]<num[i]){
                cout<<"NO";
                return 0;
            }
            if(flag2&&flag4&&num[j]>=num[i]){
                cout<<"NO";
                return 0;
            }
            if(flag1&&num[j]>=num[i]){
                flag3=true;
            }
            if(flag2&&num[j]<num[i]){
                flag4=true;
            }
        }
    }

    cout<<"YES"<<endl;
    Node* root;
    int l=0,r=n-1;
    if(num[1]<num[0])
        root = buildBSTree(l,r);
    else
        root = buildMBSTree(l,r);

    printPostOrder(root);
    cout<<que.front();
    que.pop();
    while(!que.empty()){
        cout<<" "<<que.front();
        que.pop();
    }

    return 0;
}
